package com.tt.dao;


import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.tt.entity.Food;
import com.tt.entity.User;
import com.tt.utils.MD5Util;

@SuppressWarnings("unused")
//注册
@Repository
@Transactional
public class UserDaoImpl {
	@Resource
	private SessionFactory sessionFactory;
	public int save(User user) {
		int save = (int) this.sessionFactory.getCurrentSession().save(user);
		return save;
	}
	//登录
	public User loginUser(String email,String password){
//		String pass= MD5Util.encode2hex(password);
		String hql="from User where email=? and password=?";
			Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
			query.setParameter(0, email);
			query.setParameter(1, password);
			User a =(User) query.uniqueResult();
			return a;
		
	}

	//修改
	public void updateUser(User user) {
		   
		  
		   this.sessionFactory.getCurrentSession().update(user);
		
	}
	public User toUpdateUser(Integer id){
		User user = this.sessionFactory.getCurrentSession().load(User.class, id);
		return user;
	}
	//申请升级为商家
	public boolean upgrade(User user){
		this.sessionFactory.getCurrentSession().update(user);
		return true;
	}
}
